﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace @delegate
{
    class Program
    {
        static void Main(string[] args)
        {
            // goi ham da tao thong qua delegate
            //khai bao cac doi tuong la the hien cua delegate
            ham new_ham = new ham(ham1);
            //chay ham do bang hai cach
            new_ham.Invoke("nguyen van hung");
            //ban co the chay ham tren theo cach sau
            new_ham("nguyen van hung");
            // tieptheo chung ta se goi ham co chua tham so thong qua delegate co tham so va gia tri tra ve
            //khoi tao doi tuong  cua delagate chua tham so va chua gia tri tra  ve
            delegate1 new_delegate1 = new delegate1(ham2);
            //chay ham do nhu hai cach ma toi da trinh bay o tren
            // khai bao chuoi nhan gia tri tra ve cua ham do
            string result = "";
            result = new_delegate1.Invoke("nguyen van", "hung");
            Console.WriteLine(result);
            result = new_delegate1("nguyen van", "hung");
            Console.WriteLine(result);
            
           

        }
        public  delegate void ham(string s);
        public delegate string delegate1(string  s1,string s2);
        public static void ham1(string ss)
        {
            Console.WriteLine(ss);
        }
        public static string ham2(string s1, string s2)
        {
            return s1 + s2;
        }
    
    }
}
